package org.example.preparelessons.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@ComponentScan("org.example.netdisk")//扫描控制器组件，根据自己项目的controller实际路径填写
@Configuration
public class ViewResolverConfig implements WebMvcConfigurer {
//ViewResolver(视图解析器):对于处理器适配器获取到的对象进行解析获取对应的视图最终呈现给浏览器进行渲染（比如jsp页面),ViewResolver组件是根据String类型的视图名和对应的Locale(语言环境 国际化相关)解析出View对象
    @Bean
    public ViewResolver viewResolver(){
//将JSP文件放在WEB-INF文件夹下，从而避免JSP文件可以通过手动输入的URL被直接访问，只有控制器才能访问它们
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/");
        resolver.setSuffix(".jsp");
        resolver.setViewNames("jsp/*");//当控制器返回的viewName符合规则时才使用这个视图解析器
        resolver.setOrder(2);//设置优先级,数值越小优先级越高
        return resolver;
    }
}
